#include "Landscape.h"

mtBEGIN(LandscapeDef)
	mtCONSTRUCTOR();
	mtVARIABLE(tiles);
mtEND

mtBEGIN(Landscape)
	mtBASE(ECS::Component);
	mtCONSTRUCTOR();
	mtMETHOD(initWith);
mtEND

namespace impl
{
	Landscape* _landscapeInstance = nullptr;
}

Landscape::Landscape()
{
	impl::_landscapeInstance = this;
}

Landscape::~Landscape()
{

}

Landscape* Landscape::getInstance()
{
	return impl::_landscapeInstance;
}

bool Landscape::initWith( LandscapeDef* def )
{
	_map.resize(def->tiles.getLeftX(), def->tiles.getBottomY(), def->tiles.getRightX(), def->tiles.getTopY());

	for (auto it = def->tiles.begin(); it.isValid(); ++it)
	{
		_map.setPassable(it.getX(), it.getY(), it->gid == 0);
		_map.setUserData(it.getX(), it.getY(), nullptr);
	}
	return true;
}

MapData* Landscape::getMap()
{
	return (&_map); // TODO: remove this terrible crutch
}

